package com.tron.dobest.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
@Slf4j
public class TronUserDetailsService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        TronPasswordEncoder tronPasswordEncoder = new TronPasswordEncoder();
        log.info("======用户{}进行登录校验======",s);
        User user = new User("tron","123", Arrays.asList(new SimpleGrantedAuthority("admin")));
        String encode = tronPasswordEncoder.encode("123");
        log.info("======用户密码解码或编码======原始密码：{},编码后的密码：{}",user.getPassword(),encode);
        log.info("======查询到的用户信息======:{}",user);
        return user;
    }
}
